package com.zly.service.entity;

import lombok.Data;

/**
 * 通用返回接口
 *
 * @param <T>
 */
@Data

public class Result<T> {

    private int code;

    private T data;

    private String message;

    private Long timestamp = System.currentTimeMillis();


    public static <T> Result<T> SUCCESS() {
        return Result.SUCCESS(200, "OK", null);
    }


    public static <T> Result<T> SUCCESS(T data) {
        return Result.SUCCESS(200, "OK", data);
    }


    public static <T> Result<T> SUCCESS(int code, String message, T data) {
        Result<T> result = new Result<>();
        result.setMessage(message);
        result.setCode(code);
        result.setData(data);
        return result;
    }


    public static Result<Object> ERROR() {
        Result<Object> result = new Result<>();
        result.setMessage("失败");
        result.setCode(500);
        result.setData(null);
        return result;
    }


    public static <T> Result<T> ERROR(String message) {
        return Result.ERROR(500, message, null);
    }


    public static <T> Result<T> ERROR(int code, String message) {
        return Result.ERROR(code, message, null);
    }


    public static <T> Result<T> ERROR(int code, String message, T data) {
        Result<T> result = new Result<>();
        result.setMessage(message);
        result.setCode(code);
        result.setData(data);
        return result;
    }
}
